package com.xbongbong.saas.enums;

import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.enums.business.*;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * saas列表页搜索,输入框对应搜索的字段
 *
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/1/25 13:57
 * @since v1.0
 */

@Getter
public enum ListSearchEnum {
    // 列表页搜索
    //客户
    CUSTOMER_NAME(RedundantTemplateTypeEnum.CUSTOMER.getCode(),CustomerManagementEnum.NAME.getAttr(),"",CustomerManagementEnum.NAME.getFieldType()),
    CUSTOMER_PHONE(RedundantTemplateTypeEnum.CUSTOMER.getCode(),CustomerManagementEnum.PHONE.getAttr() , "text_2",CustomerManagementEnum.PHONE.getFieldType()),
    //联系人
    CONTACT_NAME(RedundantTemplateTypeEnum.CONTACT.getCode(),ContactEnum.NAME.getAttr(),"",ContactEnum.NAME.getFieldType()),
    CONTACT_PHONE(RedundantTemplateTypeEnum.CONTACT.getCode(),ContactEnum.PHONE.getAttr() ,"text_2",ContactEnum.PHONE.getFieldType()),
    //供应商
    SUPPLIER_NAME(RedundantTemplateTypeEnum.SUPPLIER.getCode(), SupplierEnum.SUPPLIER_NAME.getAttr(), "",SupplierEnum.SUPPLIER_NAME.getFieldType()),
    //机会
    OPPORTUNITY_NAME(RedundantTemplateTypeEnum.SALES_OPPORTUNITY.getCode(), SalesOpportunityEnum.NAME.getAttr(), "",SalesOpportunityEnum.NAME.getFieldType()),
    OPPORTUNITY_NO(RedundantTemplateTypeEnum.SALES_OPPORTUNITY.getCode(), SalesOpportunityEnum.SERIAL_NO.getAttr(), "",SalesOpportunityEnum.SERIAL_NO.getFieldType()),
    //合同
    CONTRACT_NAME(RedundantTemplateTypeEnum.CONTRACT.getCode(), ContractEnum.NAME.getAttr(), "",ContractEnum.NAME.getFieldType()),
    CONTRACT_NO(RedundantTemplateTypeEnum.CONTRACT.getCode(), ContractEnum.CONTRACT_NO.getAttr(), "",ContractEnum.CONTRACT_NO.getFieldType()),
    //供应商联系人
    SUPPLIER_CONTACT_NAME(RedundantTemplateTypeEnum.SUPPLIER_CONTACT.getCode(), SupplierContactEnum.NAME.getAttr(), "",SupplierContactEnum.NAME.getFieldType()),
    SUPPLIER_CONTACT_PHONE(RedundantTemplateTypeEnum.SUPPLIER_CONTACT.getCode(), SupplierContactEnum.PHONE.getAttr(), "text_2",SupplierContactEnum.PHONE.getFieldType()),
    //采购合同
    PURCHASE_NAME(RedundantTemplateTypeEnum.PURCHASE.getCode(), PurchaseEnum.PURCHASE_NAME.getAttr(), "",PurchaseEnum.PURCHASE_NAME.getFieldType()),
    PURCHASE_NO(RedundantTemplateTypeEnum.PURCHASE.getCode(), PurchaseEnum.SHEET_NO.getAttr(), "",PurchaseEnum.SHEET_NO.getFieldType()),
    //访客计划
    COMMUNICATE_PLAN(RedundantTemplateTypeEnum.COMMUNICATE_PLAN.getCode(), CommunicatePlanEnum.NAME.getAttr(), "",CommunicatePlanEnum.NAME.getFieldType()),
    //bom单
    BOM_NAME(RedundantTemplateTypeEnum.BOMBILL.getCode(), BomBillEnum.NAME.getAttr(),"",BomBillEnum.NAME.getFieldType()),
    BOM_NO(RedundantTemplateTypeEnum.BOMBILL.getCode(), BomBillEnum.SHEET_NO.getAttr(), "",BomBillEnum.SHEET_NO.getFieldType()),
    BOM_PRODUCT_NAME(RedundantTemplateTypeEnum.BOMBILL.getCode(), BomBillEnum.PRODUCT_NAME_HIDE.getAttr(),"",BomBillEnum.PRODUCT_NAME_HIDE.getFieldType()),
    BOM_PRODUCT_NO(RedundantTemplateTypeEnum.BOMBILL.getCode(), BomBillEnum.PRODUCT_NO.getAttr(), "",BomBillEnum.PRODUCT_NO.getFieldType()),
    //仓库
    WAREHOUSE_NAME(RedundantTemplateTypeEnum.WAREHOUSE.getCode(), WarehouseEnum.WAREHOUSE_NAME.getAttr(),"",WarehouseEnum.WAREHOUSE_NAME.getFieldType()),
    WAREHOUSE_NO(RedundantTemplateTypeEnum.WAREHOUSE.getCode(), WarehouseEnum.WAREHOUSE_NO.getAttr(), "",WarehouseEnum.WAREHOUSE_NO.getFieldType()),
    //产品
    PRODUCT_NAME(RedundantTemplateTypeEnum.PRODUCT.getCode(), ProductEnum.NAME.getAttr(),"",ProductEnum.NAME.getFieldType()),
    PRODUCT_NO(RedundantTemplateTypeEnum.PRODUCT.getCode(), ProductEnum.SERIALNO.getAttr(), "",ProductEnum.SERIALNO.getFieldType()),
    PRODUCT_SPECIFICATION(RedundantTemplateTypeEnum.PRODUCT.getCode(), ProductEnum.SPECIFICATION_LINK_TEXT.getAttr(), "",ProductEnum.SPECIFICATION_LINK_TEXT.getFieldType()),
    // 盘点单
    INVENTORY_NO(RedundantTemplateTypeEnum.INVENTORY.getCode(), InventoryEnum.SHEET_NO.getAttr(), "", InventoryEnum.SHEET_NO.getFieldType()),
    //入库单
    INSTOCK_NO(RedundantTemplateTypeEnum.INSTOCK.getCode(), InstockEnum.SHEET_NO.getAttr(), "", InstockEnum.SHEET_NO.getFieldType()),
    PURCHASE_INSTOCK_NO(RedundantTemplateTypeEnum.PURCHASE_INSTOCK.getCode(), InstockEnum.SHEET_NO.getAttr(), "", InstockEnum.SHEET_NO.getFieldType()),
    REFUND_INSTOCK_NO(RedundantTemplateTypeEnum.REFUND_INSTOCK.getCode(), InstockEnum.SHEET_NO.getAttr(), "", InstockEnum.SHEET_NO.getFieldType()),
    OTHER_INSTOCK_NO(RedundantTemplateTypeEnum.OTHER_INSTOCK.getCode(), InstockEnum.SHEET_NO.getAttr(), "", InstockEnum.SHEET_NO.getFieldType()),
    PRODUCTION_INSTOCK_NO(RedundantTemplateTypeEnum.PRODUCTION_INSTOCK.getCode(), InstockEnum.SHEET_NO.getAttr(), "", InstockEnum.SHEET_NO.getFieldType()),
    RETURNED_MATERIEL_INSTOCK_NO(RedundantTemplateTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode(), InstockEnum.SHEET_NO.getAttr(), "", InstockEnum.SHEET_NO.getFieldType()),
    //出库单
    OUTSTOCK_NO(RedundantTemplateTypeEnum.OUTSTOCK.getCode(), OutstockEnum.SHEET_NO.getAttr(), "", OutstockEnum.SHEET_NO.getFieldType()),
    CONTRACT_OUTSTOCK_NO(RedundantTemplateTypeEnum.CONTRACT_OUTSTOCK.getCode(), OutstockEnum.SHEET_NO.getAttr(), "", OutstockEnum.SHEET_NO.getFieldType()),
    RETURNED_PURCHASE_OUTSTOCK_NO(RedundantTemplateTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode(), OutstockEnum.SHEET_NO.getAttr(), "", OutstockEnum.SHEET_NO.getFieldType()),
    OTHER_OUTSTOCK_NO(RedundantTemplateTypeEnum.OTHER_OUTSTOCK.getCode(), OutstockEnum.SHEET_NO.getAttr(), "", OutstockEnum.SHEET_NO.getFieldType()),
    PRODUCTION_MATERIEL_OUTSTOCK_NO(RedundantTemplateTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode(), OutstockEnum.SHEET_NO.getAttr(), "", OutstockEnum.SHEET_NO.getFieldType()),
    WORK_ORDER_OUTSTOCK_NO(RedundantTemplateTypeEnum.WORK_ORDER_OUTSTOCK.getCode(), OutstockEnum.SHEET_NO.getAttr(), "", OutstockEnum.SHEET_NO.getFieldType()),
    //装配单
    ASSEMBLE_NO(RedundantTemplateTypeEnum.ASSEMBLE.getCode(), AssembleEnum.SHEET_NO.getAttr(), "", AssembleEnum.SHEET_NO.getFieldType()),
    // 调拨单
    TRANSFER_NO(RedundantTemplateTypeEnum.TRANSFER.getCode(), TransferEnum.SHEET_NO.getAttr(), "", TransferEnum.SHEET_NO.getFieldType()),
    // 采购退货单
    RETURNED_PURCHASE_NO(RedundantTemplateTypeEnum.RETURNED_PURCHASE.getCode(), ReturnedPurchaseEnum.SHEET_NO.getAttr(), "", ReturnedPurchaseEnum.SHEET_NO.getFieldType()),
    // 生产单
    PRODUCTION_ORDER_NO(RedundantTemplateTypeEnum.PRODUCTIONORDER.getCode(), ProductionOrderEnum.SHEET_NO.getAttr(), "", ProductionOrderEnum.SHEET_NO.getFieldType()),
    PRODUCTION_ORDER_PRODUCT_NAME(RedundantTemplateTypeEnum.PRODUCTIONORDER.getCode(), ProductionOrderEnum.PRODUCT_NAME_HIDE.getAttr(),"",ProductionOrderEnum.PRODUCT_NAME_HIDE.getFieldType()),
    //客户跟进记录
    CUSTOMER_COMMUNICATE_CUSTOMER_NAME(RedundantTemplateTypeEnum.COMMUNICATE.getCode(), CustomerCommunicateEnum.CUSTOMER_NAME_LINK_TEXT.getAttr(), "", CustomerCommunicateEnum.CUSTOMER_NAME_LINK_TEXT.getFieldType()),
    //供应商跟进记录
    SUPPLIER_COMMUNICATE_SUPPLIER_NAME(RedundantTemplateTypeEnum.JXC_COMMUNICATE.getCode(), SupplierCommunicateEnum.SUPPLIER_NAME_LINK_TEXT.getAttr(), "", SupplierCommunicateEnum.SUPPLIER_NAME_LINK_TEXT.getFieldType()),
    //回款
    PAYMENT_NO(RedundantTemplateTypeEnum.PAYMENT.getCode(), PaymentEnum.PAYMENT_NO.getAttr(), "", PaymentEnum.PAYMENT_NO.getFieldType()),
    //付款
    PAY_PLAN_NO(RedundantTemplateTypeEnum.PAY_PLAN.getCode(), PayPlanEnum.PAY_PLAN_NO.getAttr(), "", PayPlanEnum.PAY_PLAN_NO.getFieldType()),
    //发票
    INVOICE_NO(RedundantTemplateTypeEnum.INVOICE.getCode(), InvoiceEnum.SHEET_NO.getAttr(), "", InvoiceEnum.SHEET_NO.getFieldType()),
    //进项发票
    PURCHASE_INVOICE_NO(RedundantTemplateTypeEnum.PURCHASE_INVOICE.getCode(), PurchaseInvoiceEnum.SHEET_NO.getAttr(),"",PurchaseInvoiceEnum.SHEET_NO.getFieldType()),
    //退货退款
    REFUND_NO(RedundantTemplateTypeEnum.REFUND.getCode(), RefundEnum.REFUND_NO.getAttr(), "", RefundEnum.REFUND_NO.getFieldType()),
    //工单
    WORKORDER_NO(RedundantTemplateTypeEnum.WORKORDER.getCode(), WorkOrderEnum.SHEET_NO.getAttr(), "", WorkOrderEnum.SHEET_NO.getFieldType()),
    WORKORDER_NAME(RedundantTemplateTypeEnum.WORKORDER.getCode(), WorkOrderEnum.NAME.getAttr(), "", WorkOrderEnum.NAME.getFieldType()),
    //报价单
    QUOTATION_NO(RedundantTemplateTypeEnum.QUOTATION.getCode(), QuotationEnum.QUOTATION_NO.getAttr(), "", QuotationEnum.QUOTATION_NO.getFieldType()),
    QUOTATION_NAME(RedundantTemplateTypeEnum.QUOTATION.getCode(), QuotationEnum.NAME.getAttr(), "", QuotationEnum.NAME.getFieldType()),
    //回款单
    PAYMENT_SHEET_NO(RedundantTemplateTypeEnum.PAYMENT_SHEET.getCode(), PaymentSheetEnum.SHEET_NO.getAttr(), "", PaymentSheetEnum.SHEET_NO.getFieldType()),
    //在线支付流水
    ONLINE_PAYMENT_FLOW(RedundantTemplateTypeEnum.ONLINE_PAYMENT_FLOW.getCode(), OnlinePaymentFlowDistributorEnum.SERIAL_NO.getAttr(), "", OnlinePaymentFlowDistributorEnum.SERIAL_NO.getFieldType()),

    REIMBURSEMENT_FORM(RedundantTemplateTypeEnum.REIMBURSEMENT_FORM.getCode(), ReimbursementFormEnum.FORM_DATA_CODE.getAttr(), "", ReimbursementFormEnum.FORM_DATA_CODE.getFieldType()),
    EXPENSE(RedundantTemplateTypeEnum.EXPENSE.getCode(), ExpenseEnum.EXPENSE_CODE.getAttr(), "", ExpenseEnum.EXPENSE_CODE.getFieldType()),
    PAY_SHEET_NO(RedundantTemplateTypeEnum.PAY_SHEET.getCode(), PaySheetEnum.PAY_PLAN_NO.getAttr(), "", PaySheetEnum.PAY_PLAN_NO.getFieldType()),

    //线索
    CLUE_NAME(RedundantTemplateTypeEnum.CLUE.getCode(), ClueEnum.COMPANY_NAME.getAttr(),"",ClueEnum.COMPANY_NAME.getFieldType()),
    CLUE_PHONE(RedundantTemplateTypeEnum.CLUE.getCode(),ClueEnum.PHONE.getAttr() , "text_2",ClueEnum.PHONE.getFieldType()),

    MARKET_ACTIVITY_NAME(RedundantTemplateTypeEnum.MARKET_ACTIVITY.getCode(), MarketActivityEnum.NAME.getAttr(),"",MarketActivityEnum.NAME.getFieldType()),
    //回款计划
    PAYMENT_TASK_NO(RedundantTemplateTypeEnum.PAYMENT_TASK.getCode(), PaymentTaskEnum.PAYMENT_TASK_NO.getAttr(), "", PaymentTaskEnum.PAYMENT_TASK_NO.getFieldType()),
    //对账单列表
    STATEMENT_NO(RedundantTemplateTypeEnum.CUSTOMER_STATEMENT_STATISTIC.getCode(), CustomerStatementStatisticEnum.STATEMENT_NO.getAttr(), "", CustomerStatementStatisticEnum.STATEMENT_NO.getFieldType()),
    // 信用管理
    CREDIT_LIMIT_NO(RedundantTemplateTypeEnum.CREDIT_LIMIT.getCode(), CreditLimitEnum.CREDIT_NO.getAttr(), "", CreditLimitEnum.CREDIT_NO.getFieldType()),
    CREDIT_TEMPORARY_NO(RedundantTemplateTypeEnum.CREDIT_TEMPORARY_LIMIT.getCode(), CreditTemporaryLimitEnum.CREDIT_TEMPORARY_NO.getAttr(), "", CreditTemporaryLimitEnum.CREDIT_TEMPORARY_NO.getFieldType()),
    CREDIT_FIXED_NO(RedundantTemplateTypeEnum.CREDIT_FIXED_LIMIT.getCode(), CreditFixedLimitEnum.CREDIT_FIXED_NO.getAttr(), "", CreditFixedLimitEnum.CREDIT_FIXED_NO.getFieldType()),
    ACCOUNT_NAME(RedundantTemplateTypeEnum.DISTRIBUTOR_ACCOUNT.getCode(),DistributorAccountEnum.NAME.getAttr(),"",DistributorAccountEnum.NAME.getFieldType()),
    ACCOUNT_PHONE(RedundantTemplateTypeEnum.DISTRIBUTOR_ACCOUNT.getCode(),DistributorAccountEnum.PHONE.getAttr(),"",DistributorAccountEnum.PHONE.getFieldType()),

    //其他收入单
    OTHER_INCOME(RedundantTemplateTypeEnum.OTHER_INCOME.getCode(), OtherIncomeEnum.SHEET_NO.getAttr(), "", OtherIncomeEnum.SHEET_NO.getFieldType()),
    //其他支出单
    OTHER_EXPENSE(RedundantTemplateTypeEnum.OTHER_EXPENSE.getCode(), OtherExpenseEnum.SHEET_NO.getAttr(), "", OtherExpenseEnum.SHEET_NO.getFieldType()),
    //资金调拨单
    FUND_TRANSFER(RedundantTemplateTypeEnum.FUND_TRANSFER.getCode(), FundTransferEnum.SHEET_NO.getAttr(), "", FundTransferEnum.SHEET_NO.getFieldType()),
    //成本调整单
    COST_ADJUST(RedundantTemplateTypeEnum.COST_ADJUST.getCode(), CostAdjustEnum.ADJUST_NO.getAttr(), "", CostAdjustEnum.ADJUST_NO.getFieldType()),
    //服务项目
    SERVICE_PROJECT_NO(RedundantTemplateTypeEnum.SERVICE_PROJECT.getCode(), FieldTypeEnum.SERIALNO.getAlias(), "", FieldTypeEnum.SERIALNO.getType()),
    SERVICE_PROJECT_NAME(RedundantTemplateTypeEnum.SERVICE_PROJECT.getCode(), "text_1", "", FieldTypeEnum.TEXT.getType()),
    //回执单
    RECEIPT_ORDER(RedundantTemplateTypeEnum.RECEIPT_ORDER.getCode(), FieldTypeEnum.SERIALNO.getAlias(), "", FieldTypeEnum.SERIALNO.getType()),
    // 工单v2.0 工单编号
    WORK_ORDER_V2_NO(RedundantTemplateTypeEnum.WORK_ORDER_V2.getCode(), FieldTypeEnum.SERIALNO.getAlias(), "", FieldTypeEnum.SERIALNO.getType()),
    // 工单v2.0 工单名称
    WORK_ORDER_V2_NAME(RedundantTemplateTypeEnum.WORK_ORDER_V2.getCode(), "text_1", "", FieldTypeEnum.TEXT.getType()),
    // sla日志 编号
    SLA_LOG_NO(XbbRefTypeEnum.SLA_LOG.getCode(), FieldTypeEnum.SERIALNO.getAlias(), "", FieldTypeEnum.SERIALNO.getType()),

    //竞争对手名称
    COMPEITOR_NAME(RedundantTemplateTypeEnum.COMPETITOR.getCode(),CompetitorEnum.NAME.getAttr(), "",CompetitorEnum.NAME.getFieldType());
    ;

    private Integer businessType;
    private String attr;
    private String subAttr;
    private Integer filedType;

    ListSearchEnum(Integer businessType, String attr,String subAttr,Integer filedType) {
        this.businessType = businessType;
        this.attr = attr;
        this.subAttr = subAttr;
        this.filedType = filedType;
    }

    public static List<String> getByBusinessType(Integer businessType,Boolean simple){
        List<String> list = new ArrayList<>();
        List<String> fieldList = BusinessFieldEnum.getByBusinessType(businessType);
        for (ListSearchEnum listSearchEnum : values()){
            if (Objects.equals(listSearchEnum.getBusinessType(),businessType)){
                String attr = listSearchEnum.attr;
                if (simple && !fieldList.contains(attr)){
                    continue;
                }
                String subAttr = listSearchEnum.subAttr;
                if (!subAttr.isEmpty()){
                    attr += "." + subAttr;
                }
                if (Objects.equals(listSearchEnum.getFiledType(),FieldTypeEnum.SERIALNO.getType())){
                    list.add("serialNo");
                }else {
                    list.add("data."+attr);
                }
            }
        }
        return list;
    }
}
